package com.gxc.event;

import com.gxc.entity.User;
import java.time.LocalDate;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

/**
 * 使用@EventListener方法实现注册事件监听.
 * @author 宫新程
 * @since 2018/12/6 11:05 AM
 */
@Component
@Slf4j
public class AnnotationRegisterListener {

  /**
   * 注册监听实现方法.
   * @param userRegisterEvent 用户注册事件
   */
  @EventListener
  @Async // 实现异步监听
  public void userRegister(UserRegisterEvent userRegisterEvent) {
    User user = userRegisterEvent.getUser();
    log.info(
        "@EventListener _____ 用户名：{}，密码：{}，时间：{}",
        user.getUsername(),
        user.getPassword(),
        LocalDate.now());
  }
}
